<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
<meta name="description" content="Arrange nodes into rectangular or elliptical areas, ignoring any links."/> 
<link rel="stylesheet" href="../assets/css/style.css"/> 
<!-- Copyright 1998-2022 by Northwoods Software Corporation. -->
<title>Packed Layout</title>
</head>

<body>
  <!-- This top nav is not part of the sample code -->
  <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
    <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2">
      <div class="md:pl-4">
        <a class="text-white hover:text-white no-underline hover:no-underline
        font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
          <h1 class="mb-0 p-1 ">GoJS</h1>
        </a>
      </div>
      <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
        <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
          <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path>
          <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path>
        </svg>
      </button>
      <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
        <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
           target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
          <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
           target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
        </ul>
      </div>
    </div>
    <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
  </nav>
  <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
    <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
    <!-- * * * * * * * * * * * * * -->
    <!-- Start of GoJS sample code -->
    
<script src="../samples/assets/require.js"></script>

    <div class="p-4 w-full">

<style type="text/css">
  input[type="number"] {
    width: 60px;
    margin-left: 3px;
  }

  input[type=checkbox], input[type=radio] {
    vertical-align: middle;
    position: relative;
    bottom: 2px;
  }
</style>
<script id="code">
  var rebuildGraph;
  function init() {
    require(["../extensionsTS/PackedScript"], function(app) {
      rebuildGraph = app.rebuildGraph;
      app.init();
      document.getElementById("randomizeGraph").onclick = app.randomize;
    });
  }
  function layout() {
    rebuildGraph();
  }
  window.addEventListener('DOMContentLoaded', init);
</script>
<div id="sample">
  <div style="margin-bottom: 5px; padding: 5px; background-color: aliceblue">
    <span style="display: inline-block; vertical-align: top; padding: 5px">
      <b>General Properties</b><br />
      PackShape:<br /> <input type="radio" name="packShape" onclick="layout()" value="Elliptical" checked> Elliptical<br />
                  <input type="radio" name="packShape" onclick="layout()" value="Rectangular"> Rectangular<br />
      PackMode:<br /> <input type="radio" name="packMode" onclick="layout()" value="AspectOnly" checked> Aspect Ratio<br />
                <input type="radio" name="packMode" onclick="layout()" value="ExpandToFit"> Expand to Fit<br />
                <input type="radio" name="packMode" onclick="layout()" value="Fit"> Fit<br />

      <table>
        <tr>
          <td>Aspect ratio: </td>
          <td><input type="number" size="2" id="aspectRatio" value="1" onchange="layout()"></td>
        </tr>
        <tr>
          <td>Layout width: </td>
          <td><input type="number" size="2" id="width" value="600" onchange="layout()"></td>
        </tr>
        <tr>
          <td>Layout height: </td>
          <td><input type="number" size="2" id="height" value="600" onchange="layout()"></td>
      </table>
    </span>
    <span style="display: inline-block; vertical-align: top; padding: 5px">
      <b>Node Sorting Properties</b><br />
      SortOrder: <input type="radio" name="sortOrder" onclick="layout()" value="Descending" checked> Descending
                  <input type="radio" name="sortOrder" onclick="layout()" value="Ascending"> Ascending<br />
      SortMode: <br />
        <input type="radio" name="sortMode" onclick="layout()" id="modeNone" value="None"> None (do not sort nodes)<br />
        <input type="radio" name="sortMode" onclick="layout()" id="modeMaxSide" value="MaxSide"> Max Side Length<br />
        <input type="radio" name="sortMode" onclick="layout()" id="modeArea" value="Area" checked> Area<br />

      <b>Padding between nodes</b><br />
        Spacing: <input type="number" id="nodeSpacing" value="0" onchange="layout()"><br />
      <b>Circle Packing</b><br />
        hasCircularNodes <input type="checkbox" id="hasCircularNodes" onclick="layout()"><br />
        isSpiralPacked <input type="checkbox" id="isSpiralPacked" onclick="layout()">
    </span>

    <span style="display: inline-block; vertical-align: top; padding: 5px">
      <b>Node Generation</b><br />
      <table>
        <tr>
          <td>Number of nodes: </td>
          <td><input type="number" id="numNodes" value="100" onchange="layout()"><br /></td>
        </tr>
        <tr>
          <td>Node shape:<br /><input type="radio" name="shapeToPack" onclick="layout()" value="Rectangle" checked> Rectangles<br />
                              <input type="radio" name="shapeToPack" onclick="layout()" value="Ellipse"> Ellipses<br />
        </tr>
        <tr>
          <td>Minimum side length: </td>
          <td><input type="number" id="nodeMinSide" value="30" onchange="layout()"><br /></td>
        </tr>
        <tr>
          <td>Maximum side length: </td>
          <td><input type="number" id="nodeMaxSide" value="50" onchange="layout()"><br /></td>
        </tr>
      </table>
      Same width/height <input type="checkbox" id="sameSides" onclick="layout()"><br />
      <button type="button" id="randomizeGraph" style="margin-top: 5px;">Randomize Graph</button>
    </span>
  </div>
  <div id="myDiagramDiv" style="background-color: white; border: solid 1px black; width: 100%; height: 500px"></div>
  <p>
    This sample demonstrates a custom Layout, PackedLayout, which attempts to pack nodes as close together as possible without overlap.
    Each node is assumed to be either rectangular or circular (dictated by the 'nodesAreCircles' property). This layout supports packing
    nodes into either a rectangle or an ellipse, with the shape determined by the PackShape and the aspect ratio determined by either the
    aspectRatio property, or the specified width and height (depending on the PackMode).
  </p>
  <p>
    This extension's code is TypeScript-only and the source files can be found in the <code>extensionsTS</code> directory.
    The layout is defined in its own file, as <a href="../extensionsTS/PackedLayout.ts">extensionsTS/PackedLayout.ts</a>, with an additional dependency on <a href="../extensionsTS/Quadtree.ts">extensionsTS/Quadtree.ts</a>.
  </p>
</div>
    </div>
    <!-- * * * * * * * * * * * * * -->
    <!--  End of GoJS sample code  -->
  </div>
</body>
<!--  This script is part of the gojs.net website, and is not needed to run the sample -->
<script src="../assets/js/goSamples.js"></script>
</html>
